package com.leihao.product.service.impl;

import com.leihao.product.domian.ProductLadder;
import com.leihao.product.mapper.ProductLadderMapper;
import com.leihao.product.service.ProductLadderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class ProductLadderServiceImpl implements ProductLadderService {
    @Autowired
    private ProductLadderMapper productLadderMapper;

    @Override
    public void addBatch(List<ProductLadder> list) {
        if (CollectionUtils.isEmpty(list)) {
            throw new RuntimeException("商品阶梯价格列表不能为空");
        }
        productLadderMapper.addBatch(list);
    }
    @Override
    public void update(ProductLadder productLadder) {
        if (productLadder == null) {
            throw new RuntimeException("商品阶梯价格不能为空");
        }
        if (productLadder.getProductLadderId() == null) {
            throw new RuntimeException("商品阶梯价格ID不能为空");
        }
        productLadderMapper.update(productLadder);
    }

    @Override
    public void deleteLadderList(Integer productId) {
        if (productId == null){
            throw new RuntimeException("商品ID不能为空");
        }
        productLadderMapper.deleteLadderList(productId);
    }
}
